<template>
  <div class="container">
    <yd-navbar title="折扣管理">
      <router-link to slot="left">
        <yd-navbar-back-icon @click.native="$router.back()"></yd-navbar-back-icon>
      </router-link>
      <router-link
        to="/business/cutDetail?type=add"
        slot="right"
        style="color:#5c5c5c;font-size:14px;"
      >添加折扣</router-link>
    </yd-navbar>
    <div class="cplist">
      <div class="rmlist">
        <div class="remitem" v-for="(item, index) in list" :key="index">
          <img :src="bgs[index % bgs.length]" alt />
          <div class="cpleft" @click="$router.push('/business/cutDetail?id='+item.id)">
            <div class="cptitle">
              <span>{{ item.title }}</span>
            </div>
            <span class="status">{{ item.open === 1 ? '已启用' : '已禁用' }}</span>
            <div class="monsl">折扣内容： {{ item.content }}</div>
          </div>
          <div class="cpright">
            <!-- <router-link to @click.native="$dialog.toast({mes:'修改'})">修改</router-link> -->
            <span @click="()=>update(item,{open:-item.open}, item.open === 1 ? '启用' : '禁用')">
              {{
              item.open === 1 ? '启用' : '禁用'
              }}
            </span>
            <span style="color:red" @click="()=>update(item,{vaild:-item.vaild}, '删除')">删除</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import businessMenu from "@/components/business_detail/menu";
import { getDiscountGoods, discountGoodsUpdate } from "@/api";
export default {
  name: "shopList",
  data() {
    return {
      list: [],
      bgs: [
        require("../../image/美食1.jpeg"),
        require("../../image/美食2.jpeg"),
        require("../../image/美食3.jpeg")
      ],
      pageParams: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  components: {
    businessMenu
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      getDiscountGoods({
        ...this.pageParams,
        request: {
          bussinesId: 1
        }
      }).then(res => {
        this.list = res.data ? res.data.result : [];
      });
    },
    update(item, updateVal, text = "") {
      this.$dialog.confirm({
        title: "确认？",
        mes: `确定${text}这个折扣？`,
        opts: () => {
          discountGoodsUpdate({
            ...item,
            ...updateVal
          }).then(res => {
            this.$dialog.toast({
              mes: `${text}成功`,
              type: "success",
              timeout: 800
            });
            this.getData();
          });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.cpleft {
  text-align: left;
  flex: 1;
  flex-direction: column;
  display: flex;
}

.cplist {
  margin: 0.1rem 0rem;
  background: transparent;
}

.rmlist {
  padding: 0 0.2rem;
}

.remitem {
  border-radius: 0.2rem;
  display: flex;
  padding: 0.2rem 0.4rem;
  margin: 0.15rem 0;
  background-size: 100% 100%;
  position: relative;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  overflow: hidden;

  &:hover {
    cursor: pointer;
  }

  img {
    width: 100%;
    position: absolute;
    z-index: -1;
    left: 0;
    top: 0;
  }
}

.cpright {
  width: 15%;
  text-align: right;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-direction: column;

  span {
    font-size: 0.28rem;
    line-height: 0.5rem;

    &:hover {
      color: green;
    }
  }
}

.cptitle {
  font-size: 0.32rem;
  font-weight: bold;
  line-height: 0.6rem;
  color: #eee;
}

.status {
  width: 0.8rem;
  font-size: 0.24rem;
  color: #fff;
  padding: 0.02rem;
  background: rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.cpyp {
  color: #999;
  line-height: 0.4rem;
}

.cpyp span {
  padding-right: 0.3rem;
}

.monsl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.15rem;
}

.monsl span {
  font-size: 0.33rem;
  color: red;
  padding-right: 0.15rem;
}
</style>
